If you store your component in a component resource and register your component using the RegisterComponentResource function or RegisterComponentResourceFile function, or if the Component Manager automatically registers your component, the Component Manager allows your component to gain access to its resource file. You can store read-only data for your component in its resource file. For example, the resource file may contain the color icon for the component, static data needed to initialize private storage, or any other data that may be useful to the component. Note that there is only one resource file associated with a component.
If you store your component in a component resource but register the component with the RegisterComponent function, rather than with the RegisterComponentResource or RegisterComponentResourceFile function, your component cannot access its resource file with the routines described in this section.
The routines described in this section allow your component to gain access to its resource file. These routines provide read-only access to the data in the resource file. If your component opens its resource file, it must close the file before returning to the calling application.
Use the OpenComponentResFile function to open your component's resource file. Use the CloseComponentResFile function to close the resource file before returning to the calling application.
The OpenComponentResFile function allows your component to gain access to its resource file. This function opens the resource file with read permission and returns a reference number that your component can use to read data from the file. The Component Manager adds the resource file to the current resource chain. Your component must close the resource file with the CloseComponentResFile function before returning to the calling application.
Your component can use FSpOpenResFile or equivalent Resource Manager routines to open other resource files, but you must use OpenComponentResFile to open your component's resource file.
FUNCTION OpenComponentResFile (aComponent: Component): Integer;
The OpenComponentResFile function returns a reference number for the appropriate resource file. This function returns 0 or a negative number if the specified component does not have an associated resource file or if the Component Manager cannot open the resource file.
Note that when working with resources, your component should always first save the current resource file, perform any resource operations, then restore the current resource file to its previous value before returning.
This function closes the resource file that your component opened previously with the OpenComponentResFile function.
FUNCTION CloseComponentResFile (refnum: Integer): OSErr;